<script>
	import {
		recommend
	} from '@/api/public.js'
	import {
		BASE_URL,
	} from '@/config/app';
	import {
		mapGetters
	} from "vuex";
	export default {
		computed: mapGetters(["isLogin", "app_token", "user_id"]),
		globalData: {
			parent_id: 0, //分享者的user_id
			screenHeight: 0, // 屏幕尺寸
			screenWidth: 0, // 屏幕尺寸
			windowHeight: 0,
			isLogin: false,
			userInfo: {},
			theme_color: '#EF1C25',
			supplier_id: 633,//633 616
			market: 0,
			recommend_id:0,
			card_bg_list: [
				BASE_URL + '/statics/yilangmp/card/card_bg1.png',
				BASE_URL + '/statics/yilangmp/card/card_bg2.png',
				BASE_URL + '/statics/yilangmp/card/card_bg3.png',
				BASE_URL + '/statics/yilangmp/card/card_bg4.png',
				BASE_URL + '/statics/yilangmp/card/card_bg5.png',
				BASE_URL + '/statics/yilangmp/card/card_bg6.png',
			],
		},
		onLaunch: function(option) {
			let that = this
			console.log('青泓 App Launch')
			console.log(option)
			//扫码进来
			let obj = that.$util.getUrlParams(decodeURIComponent(option.query.scene), ',');
			
			console.log(obj)
			
			if (obj.sid) {
				that.$Cache.set('PARENT_ID', parseInt(obj.sid));
				that.globalData.parent_id = parseInt(obj.sid);
				that.$store.commit("UPDATE_PARENT_ID", parseInt(obj.sid))
				console.log('parent_id------', parseInt(obj.sid))
			}
			
			
			//绑定者id
			if (option.query.rid) {
				console.log(option.query.rid)
				that.$Cache.set('RECOMMEND_ID', parseInt(option.query.rid));
				that.globalData.recommend_id = parseInt(option.query.rid);
				that.$store.commit("UPDATE_RECOMMEND_ID", parseInt(option.query.rid))
				console.log('recommend_id------', parseInt(option.query.rid))
				if (this.isLogin) {
					recommend({
						app_token: this.app_token,
						parent_id: option.query.rid,
						supplier_id: this.globalData.supplier_id
					}).then(res => {
						console.log('绑定推荐人', res.msg)
					})
				}
			}
			
			
			this.globalData.screenHeight = uni.getSystemInfoSync().screenHeight;
			this.globalData.screenWidth = uni.getSystemInfoSync().screenWidth;
			this.globalData.windowHeight = uni.getSystemInfoSync().windowHeight;
			
			uni.getSystemInfo({
				success: function(e) {
			
					let statusBar = 0 //状态栏高度
					let customBar = 0 // 状态栏高度 + 导航栏高度  
					let navbar = 0 // 自定义标题与胶囊对齐高度
			
					that.globalData.navHeight = e.statusBarHeight * (750 / e.windowWidth) + 91;
					that.globalData.screenWidth = e.windowWidth;
					// #ifdef MP-WEIXIN
					that.globalData.statusBar = e.statusBarHeight
					const custom = wx.getMenuButtonBoundingClientRect()
					that.globalData.customBar = custom.bottom + custom.top - e.statusBarHeight
			
					that.globalData.navbar = (custom.top - e.statusBarHeight) * 2 + custom.height
					// #endif
			
				}
			})
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	@import "@/uni_modules/uview-ui/index.scss";
	@import 'static/css/base.css';
	@import 'static/css/common.scss';
	@import 'static/iconfont/iconfont.css';

	page {
		background-color: #ffffff;
	}
</style>
